/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package geradores;

import dominio.Cliente;
import dominio.Relatorio;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author gilcemar e naliane
 */
public class GeradorRelatorioJasper {

    String reportSource = "C:/Users/gilcemar e naliane/Documents/PASTA GILCEMAR/repositorio teste/hg/hg/TraxxProjeto/relatorios/relatorio Mensal de vendas.jrxml";
    String reportDest = "C:/Users/gilcemar e naliane/Documents/PASTA GILCEMAR/repositorio teste/hg/hg/TraxxProjeto/relatorios/relatorio Mensal de vendas.pdf";
    Map<String, Object> params = new HashMap<String, Object>();

    public void gerarRelatorio(List<Relatorio> relatorio) {
        try {
            JasperReport jasperReport = null;
            try {
                jasperReport = JasperCompileManager.compileReport(reportSource);
            } catch (JRException ex) {
                Logger.getLogger(GeradorRelatorioJasper.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                JRBeanCollectionDataSource jrBean = new JRBeanCollectionDataSource(relatorio);
                JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, jrBean);
                JasperExportManager.exportReportToPdfFile(jasperPrint, reportDest);
                JasperViewer.viewReport(jasperPrint);
            } catch (JRException ex) {
                ex.printStackTrace();
            }
        } catch (Exception e) {
        }
    }
}
